﻿using System;

namespace DotNetImage.Imaging.Filters
{
    public class ColorShiftFilter : FilterBase
    {
        private long RedShift;
        private long GreenShift;
        private long BlueShift;

        /// <summary>
        /// Shift the red channel in percents: from -100% (no color) to +100% (full color). 0 - no changes in the color.
        /// </summary>
        [ParameterAttribute(Name = "Red", DefaultValue = 0, MinValue = -100, MaxValue = 100, Step = 0.1)]
        public double Red { get; set; }

        /// <summary>
        /// Shift the green channel in percents: from -100% (no color) to +100% (full color). 0 - no changes in the color.
        /// </summary>
        [ParameterAttribute(Name = "Green", DefaultValue = 0, MinValue = -100, MaxValue = 100, Step = 0.1)]
        public double Green { get; set; }

        /// <summary>
        /// Shift the blue channel in percents: from -100% (no color) to +100% (full color). 0 - no changes in the color.
        /// </summary>
        [ParameterAttribute(Name = "Blue", DefaultValue = 0, MinValue = -100, MaxValue = 100, Step = 0.1)]
        public double Blue { get; set; }

        protected override void ValidateArguments()
        {
            Validator.ValidateInclusiveRange("Red", Red, -100, 100);
            Validator.ValidateInclusiveRange("Green", Red, -100, 100);
            Validator.ValidateInclusiveRange("Blue", Red, -100, 100);
        }

        protected override void PrepareData(DotNetImage bmp)
        {
            base.PrepareData(bmp);
            RedShift = (long)(this.Red / 100 * bmp.ColorChannelMaxValue);
            GreenShift = (long)(this.Green / 100 * bmp.ColorChannelMaxValue);
            BlueShift = (long)(this.Blue / 100 * bmp.ColorChannelMaxValue);
        }

        protected override void ProcessPixel(ref Pixel pix, uint x, uint y)
        {
            pix.AddRGB(RedShift, GreenShift, BlueShift);
        }

    }
}
